
ESCAPE = {
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;'
}

$.extend(
    $
    {
        escape : (str) =>
            # Here is a performance test: http://jsperf.com/encode-html-entities to compare with calling the replace function repeatedly, and using the DOM method proposed by Dmitrij.
            return str.replace(/[&<>]/g, (tag)=>ESCAPE[tag] || tag)
    }
)
